package org.example.acl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.acls.domain.AclAuthorizationStrategy;
import org.springframework.security.acls.domain.AclImpl;
import org.springframework.security.acls.domain.AuditLogger;
import org.springframework.security.acls.model.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
class MyAclService implements AclService, MutableAclService {

    private static final Sequence aclIdSeq = new InMemorySequence();

    private final List<Acl> aclList = new ArrayList<>();

    @Autowired
    private AclAuthorizationStrategy aclAuthorizationStrategy;

    @Autowired
    private AuditLogger auditLogger;


    @Override
    public List<ObjectIdentity> findChildren(ObjectIdentity parentIdentity) {
        return null;
    }

    @Override
    public Acl readAclById(ObjectIdentity object) throws NotFoundException {
        return aclList.stream()
                .filter(acl -> acl.getObjectIdentity().equals(object))
                .findFirst()
                .orElse(null);
    }

    @Override
    public Acl readAclById(ObjectIdentity object, List<Sid> sids) throws NotFoundException {
        return null;
    }

    @Override
    public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects) throws NotFoundException {
        return null;
    }

    @Override
    public Map<ObjectIdentity, Acl> readAclsById(List<ObjectIdentity> objects, List<Sid> sids) throws NotFoundException {
        return null;
    }

    @Override

    public MutableAcl createAcl(ObjectIdentity objectIdentity) throws AlreadyExistsException {
        MutableAcl acl = new AclImpl(objectIdentity, aclIdSeq.next(),
                aclAuthorizationStrategy, auditLogger);
        aclList.add(acl);
        return acl;
    }

    @Override
    public void deleteAcl(ObjectIdentity objectIdentity, boolean deleteChildren) throws ChildrenExistException {

    }

    @Override
    public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
        return null;
    }
}

